<div class="row-fluid">
<div class="span10">
<header><i class="icon-list"></i> Worksheet of <?php echo ucfirst($get_user['username']); ?> for the month of <?php echo($current_month);?></header>

<style>
	.details{
		width:190px;
	}
	
	.feed_red{
		background-color:rgb(255, 0, 0);
		width: 2px;
		height: 20px;
	}
	.feed_green{
		background-color:rgb(0, 204, 102);
		width: 2px;
		height: 20px;
	}
	.feed_yellow{
		background-color:rgb(255, 255, 0);
		width: 2px;
		height: 20px;
	}
	
	.tag_options{
		padding: 5px;
		border: 1px solid #ccc;
		margin: 0px;
	}
	
	.tag_options:hover{
		background-color: #ded9f7;
		color: #fff;
		cursor: pointer
	}

</style>
<br>

<?php
if(!isset($hashtag)){?>

<table class="table table-striped table-bordered table-condensed">
 <tr><th>  <b class="text-info">[Enter]</b> : For New Row   ||   <b class="text-success">[Delete]</b> : To delete a Row</th></tr>
</table>


<form action="<?php echo site_url('user/worksheet/insert_multiple_worksheet');?>" id="multiple_form" method="POST">
 	<input type="hidden" name="users_ids" value="<?= $get_user['id'];?>">
	<div class="test">
	<input type="text" name="date[0]" class="datepicker multiple_subtask details span3" id="date" value="<?php echo date('Y-m-d')?>" />  
  	<input type="text" name="task_details[0]" placeholder="your task description..." class="multiple_subtask span6 tag" id="desc0" autocomplete="off" />   
  
  	<input type="text" class="multiple_subtask span1" name="time_hr[0]" id="hr" value="00" />
  	<input type="text" class="multiple_subtask span1" name="time_min[0]" id="min" value="00" />
	</div>
	
	
	<!---New 1 start--->
	<div class="test1" style="display: none">
	
	<input type="text" name="date[1]" class="datepicker multiple_subtask details span3" id="date" value="<?php echo date('Y-m-d')?>" /> 
  	<input type="text" name="task_details[1]" placeholder="your task description..." class="multiple_subtask span6 tag" id="desc1" autocomplete="off" />   
  	<input type="text" class="multiple_subtask span1" name="time_hr[1]" id="hr" value="00" />
  	<input type="text" class="multiple_subtask span1" name="time_min[1]" id="min" value="00" />
	</div>
	<!---New 1 end--->
	
	<!---New 2 start--->
	
	<div class="test2" style="display: none">
	<input type="text" name="date[2]" class="datepicker multiple_subtask details span3" id="date" value="<?php echo date('Y-m-d')?>" /> 
  	<input type="text" name="task_details[2]" placeholder="your task description..." class="multiple_subtask span6 tag" id="desc2" autocomplete="off" />   
  	<input type="text" class="multiple_subtask span1" name="time_hr[2]" id="hr" value="00" />
  	<input type="text" class="multiple_subtask span1" name="time_min[2]" id="min" value="00" />
	</div>
	<!---New 2 end--->
	
	<!---New 3 start--->
	
	<div class="test3" style="display: none">
	<input type="text" name="date[3]" class="datepicker multiple_subtask details span3" id="date" value="<?php echo date('Y-m-d')?>" /> 
  	<input type="text" name="task_details[3]" placeholder="your task description..." class="multiple_subtask span6 tag" id="desc3" autocomplete="off" />   
  	<input type="text" class="multiple_subtask span1" name="time_hr[3]" id="hr" value="00" />
  	<input type="text" class="multiple_subtask span1" name="time_min[3]" id="min" value="00" />
	</div>
	<!---New 3 end--->
	
	<!---New 4 start--->
	
	<div class="test4" style="display: none">
	<input type="text" name="date[4]" class="datepicker multiple_subtask details span3" id="date" value="<?php echo date('Y-m-d')?>" /> 
  	<input type="text" name="task_details[4]" placeholder="your task description..." class="multiple_subtask span6 tag" id="desc4" autocomplete="off" />   
  	<input type="text" class="multiple_subtask span1" name="time_hr[4]" id="hr" value="00" />
  	<input type="text" class="multiple_subtask span1" name="time_min[4]" id="min" value="00" />
	</div>
	<!---New 4 end--->
	
	<!---New 5 start--->
	
	<div class="test5" style="display: none">
	<input type="text" name="date[5]" class="datepicker multiple_subtask details span3" id="date" value="<?php echo date('Y-m-d')?>" /> 
  	<input type="text" name="task_details[5]" placeholder="your task description..." class="multiple_subtask span6 tag" id="desc5" autocomplete="off" />   
  	<input type="text" class="multiple_subtask span1" name="time_hr[5]" id="hr" value="00" />
  	<input type="text" class="multiple_subtask span1" name="time_min[5]" id="min" value="00" />
	</div>
	<!---New 5 end--->
	
	<!---New 6 start--->
	
	<div class="test6" style="display: none">
	<input type="text" name="date[6]" class="datepicker multiple_subtask details span3" id="date" value="<?php echo date('Y-m-d')?>" /> 
  	<input type="text" name="task_details[6]" placeholder="your task description..." class="multiple_subtask span6 tag" id="desc6" autocomplete="off" />   
  	<input type="text" class="multiple_subtask span1" name="time_hr[6]" id="hr" value="00" />
  	<input type="text" class="multiple_subtask span1" name="time_min[6]" id="min" value="00" />
	</div>
	<!---New 6 end--->
	
	<!---New 7 start--->
	
	<div class="test7" style="display: none">
	<input type="text" name="date[7]" class="datepicker multiple_subtask details span3" id="date" value="<?php echo date('Y-m-d')?>" /> 
  	<input type="text" name="task_details[7]" placeholder="your task description..." class="multiple_subtask span6 tag" id="desc7" autocomplete="off" />   
  	<input type="text" class="multiple_subtask span1" name="time_hr[7]" id="hr" value="00" />
  	<input type="text" class="multiple_subtask span1" name="time_min[7]" id="min" value="00" />
	</div>
	<!---New 7 end--->
	
	
		
  	<div id="insert_subtask"></div>   
  <input type="button" class="btn btn-success btn-small" onclick="formSubmit()" name="save" value="Save All" id="save_multiple" />
  </form>

<?php } ?>

<?php if($this->ion_auth->is_admin()){ ?>
	<input type="submit" value="Verify" class="btn btn-info" id="verify" style="float: left; margin-bottom: 10px"/>
<?php } ?>

<table width="100%" class="table table-bordered table-striped">
<form action="<?php echo site_url('user/worksheet/verify_worksheet');?>" id="multiple_submit" method="POST">	
<thead>
	<tr>
		<th width="20%">Timings 
		<?php if($this->ion_auth->is_admin()){ ?>
			<input type="checkbox" name="all" id="all" onchange="select_all();" value="all" style="float: right;"></th>
		<?php } ?>
		<th width="60%">Task(s)</th>		
		<th width="20%">Overall</th>		
	</tr>
	</thead>
	<tbody>	
	<?php foreach($worksheet as $ws){ ?>
		<tr>
			<td>
			<?= date("F", mktime(0, 0, 0, $ws->month_id, 10))?> <?php echo $ws->date_id?>

			<?php
			$where = array(
				'year_id' 	=> 	$ws->year_id,
				'month_id' 	=>	$ws->month_id,				
				'user_id'	=>	$ws->user_id,	
				'date_id'	=> 	$ws->date_id,
				);	
		$get_work_verify = $this->worksheet_model->get_worksheet_verify($where);
		foreach($get_work_verify as $vid)
		{
		if(!empty($get_work_verify))
		{
		if($ws->user_id == $vid->user_id){?>
			<img src="<?= $this->config->base_url(); ?>assets/img/tick.png" class="tooltips" title="Verified">
			<?php }}}?>
						
			<?php if($this->ion_auth->is_admin()){ ?>
			<input type="hidden" name="user_id[]" value="<?= $ws->user_id; ?>"/>
	<input type="hidden" name="year_id[]" value="<?= $ws->year_id; ?>"/>
	<input type="hidden" name="month_id[]" value="<?= $ws->month_id; ?>"/>	
				<a style="float: right"><input type="checkbox" name="date_id[]" class="alls" value="<?= $ws->date_id; ?>"/></a>
			<?php } ?>
			<br><br>
			<?php
				//$attendance = $this->worksheet_model->get_attendance_timings($user_id,date('y'),date('m'),date('d'));
				$attendance = $this->worksheet_model->get_attendance_timings($user_id,$ws->year_id,$ws->month_id,$ws->date_id);	
			foreach($attendance as $at){
				if(isset($at->entry_time))
				{
			echo '<table class="table table-striped table-condensed" width="100%">';
			echo '<tr><td width="55%"><b class="text-success">Entry:</b>&nbsp;</td>';
			echo '<td width="45%">';
			if(!empty($at->entry_time)){
			echo date("g:i a", strtotime($at->entry_time));
			}
			echo '</td></tr>';	
			echo '<tr><td><b class="text-warning">Lunch In:</b>&nbsp;</td>';
			echo '<td>';
			if(!empty($at->lunch_in_time)){
			echo date("g:i a", strtotime($at->lunch_in_time));
			}
			echo '</td></tr>';
			echo '<tr><td><b class="text-info">Lunch Out:</b>&nbsp;</td>';
			echo '<td>';
			if(!empty($at->lunch_out_time)){
			echo date("g:i a", strtotime($at->lunch_out_time));
			}
			echo '</td></tr>';
			echo '<tr><td><b class="text-danger">Exit:</b>&nbsp;</td>';	
			echo '<td>';
			if(!empty($at->exit_time)){
			echo date("g:i a", strtotime($at->exit_time));
			}
			echo '</td></tr>';
			echo '</table>';			
			
			}}?>

				
			</td>
			<td>
			<table width="100%" class="table table-condensed table-bordered">
			<?php
			$dbtime_tot = 0; 
			$tot_working_hr = 0;
			if(!empty($hashtag)){
			$descs = $this->worksheet_model->get_worksheet_date_time_hashtag($user_id,$ws->year_id,$ws->month_id,$ws->date_id,$hashtag);			}else{
			$descs = $this->worksheet_model->get_worksheet_date_time($user_id,$ws->year_id,$ws->month_id,$ws->date_id);	
			}
			
				foreach($descs as $des){?>
					<tr>
					<td width="1%">
						<?php $feed=$des->feed; 
				if($feed=="1"){
					echo '<div class="feed_red"></div>';
				}elseif($feed=="2"){
					echo '<div class="feed_green"></div>';
				}elseif($feed=="3"){
					echo '<div class="feed_yellow"></div>';
				}else{
					echo '<div class="feed_green"></div>';
				}
				?>
					</td>
					 <td width="69%">
					 		<?php $flag=$des->edited_flag;
							if(!empty($flag) && $flag==1): 
							echo '<span class="text-warning">'.$des->desc;
							else:	
							echo $des->desc;
							endif;	
							?>
					 </td>					
					 <td width="15%"><?= $des->time_spent; ?></td>
					 <td width="15%">
					 
					 <?php
					 	$where = array(
				'year_id' 	=> 	$ws->year_id,
				'month_id' 	=>	$ws->month_id,				
				'user_id'	=>	$ws->user_id,	
				'date_id'	=> 	$ws->date_id,
				);	
		$get_work_verify = $this->worksheet_model->get_worksheet_verify($where);
					 	if(empty($get_work_verify)){
						?>
																 				
					<a href="<?php echo site_url('user/worksheet/delete_worksheet').'/'.$des->id.'/'.$des->user_id.'/'.$des->year_id.'/'.$des->month_id?>"><i class="icon-trash"></i></a>	&nbsp;
					<a href="<?php echo site_url('user/worksheet/get_worksheet/'.$des->id);?>" class="get_worksheet"><i class="icon-edit"></i></a>
					
					<?php if($this->ion_auth->is_admin()){ ?>
				<div class="dropdown" style="float: right">
					<a class="dropdown-toggle" data-toggle="dropdown" href="#"><i class="icon-cogs"></i>
  				<b class="caret"></b>
 					</a>
  				<ul class="dropdown-menu" role="menu" aria-labelledby="dLabel">
  					<li><a class="red" style="cursor:pointer;" data-id="<?php echo $des->id ?>" data-color="1" ><i class="icon-ok-sign"></i> <span class="text-error">Red</span></a></li>
  					<li><a class="green" style="cursor:pointer;" data-id="<?php echo $des->id ?>" data-color="2" ><i class="icon-ok-sign"></i> <span class="text-error">Green</span></a></li>
					<li><a class="yellow" style="cursor:pointer" data-id="<?php echo $des->id ?>" data-color="3" ><i class="icon-ok-sign"></i> <span class="text-error">Yellow</span></a></li>
  				</ul>
				</div>
					
					
					<?php }} ?>
					
					</td>
					</tr>					
				<?php }?>
				</table>
					
				  <!--Progress Bar starts-->				
			<?php
			$dbtime_tot = 0; 
			$tot_working_hr = 0;
			if(!empty($hashtag)){		
			$descs = $this->worksheet_model->get_worksheet_date_time_hashtag($user_id,$ws->year_id,$ws->month_id,$ws->date_id,$hashtag);
			}else	{
				$descs = $this->worksheet_model->get_worksheet_date_time($user_id,$ws->year_id,$ws->month_id,$ws->date_id);
			}	
				foreach($descs as $des){?>
						
										
					<?php					
					$dbtime_explode = explode(':',$des->time_spent);
		 			$dbtot_hr 		= $dbtime_explode[0]*60*60;
					$dbtot_min		= $dbtime_explode[1]*60;				
					$dbtime_tot 	+= $dbtot_hr + $dbtot_min;
					
					//echo $des->date_id;
					//get total time working time;
					
					$uID = isset($user_id) ? $user_id : $this->session->userdata('user_id');
					if($ws->date_id < 10):
					$dID = 'day_0'.$ws->date_id;
					//echo $ws->date_id;
					else:
					$dID = 'day_'.$ws->date_id;
					endif;
					
					//echo $mID = ($des->month_id < 10) ? echo '0'.$des->month_id < 10 : echo ($des->month_id < 10);
					
					if($des->month_id < 10):
					$mID = '0'.$des->month_id;
					else:
					$mID = $des->month_id ;
					endif;
					
					$where = array(
					'year_id' 	=> $des->year_id,
					'month_id'	=> $mID,
					'user_id' 	=> $uID,					
					);
					//$break_time = 0;
					?>					
				<?php }?>
				
				
				<?php
					$attendance = $this->worksheet_model->get_attendance_timings($user_id,$ws->year_id,$ws->month_id,$ws->date_id);
				foreach($attendance as $at){	
		
				if(!empty($at->entry_time) && !empty($at->lunch_in_time) && !empty($at->lunch_out_time) && !empty($at->exit_time))
				{				
			/*	$tt = $this->worksheet_model->get_total_working_hr($where,$dID);
				if(!empty($tt)):
				$bt = explode(':',$tt);
				$a=$bt[1]*60;
				$bt_hr 		= $bt[0]*60*60;
				$bt_min		= $bt[1]*60;
				$tot_working_hr =  $bt_hr + $bt_min;
				endif;*/
				
				$dbtime_ent = explode(':',$at->entry_time);
		 		$dbtot_hre 		= $dbtime_ent[0]*60*60;
				$dbtot_mine		= $dbtime_ent[1]*60;				
				$dbtime_tot_ent = $dbtot_hre + $dbtot_mine;
				
				$dbtime_ext = explode(':',$at->exit_time);
		 		$dbtot_hrb 		= $dbtime_ext[0]*60*60;
				$dbtot_minb		= $dbtime_ext[1]*60;				
				$dbtime_tot_ext = $dbtot_hrb + $dbtot_minb;
				
				$tot=$dbtime_tot_ext-$dbtime_tot_ent;

				$dbtime_lit = explode(':',$at->lunch_in_time);
		 		$dbtot_hr 		= $dbtime_lit[0]*60*60;
				$dbtot_min		= $dbtime_lit[1]*60;				
				$dbtime_tot_lit = $dbtot_hr + $dbtot_min;
				
				$dbtime_lot = explode(':',$at->lunch_out_time);
		 		$dbtot_hr 		= $dbtime_lot[0]*60*60;
				$dbtot_min		= $dbtime_lot[1]*60;				
				$dbtime_tot_lot = $dbtot_hr + $dbtot_min;
				
				$lunch_time=$dbtime_tot_lot-$dbtime_tot_lit;
				
				$break_time = ($tot - $dbtime_tot)- $lunch_time;
				$bl = $break_time + $lunch_time;
				$blhours 		= floor(abs($bl)/ 3600);
				$blminutes 		= floor((abs($bl) / 60) % 60);
				$break_lunch	= $blhours .' hr : '.$blminutes.' min';
				
				$tbhours 		= floor(abs($dbtime_tot)/ 3600);
				$tbminutes 		= floor((abs($dbtime_tot) / 60) % 60);
				$totalwork=  $tbhours .' hr : '.$tbminutes.' min';
				
				$bhours 		= floor(abs($break_time)/ 3600);
				$bminutes 		= floor((abs($break_time) / 60) % 60);
				$break=  $bhours .' hr : '.$bminutes.' min';
				
				if(!empty($tot))
				{
				$work_percent = ($dbtime_tot/$tot)*100;
				$wt=round($work_percent).'%';
				
				$break_percent = ($bl/$tot)*100;
				$bt=round($break_percent).'%';
				}
				if(!empty($tot))
				{
				?>
							 <div class="progress  progress-striped active" style="height: 5px; margin-top:-10px">			
    <div class="bar bar-success tooltips" title="Work: <?php echo $totalwork ?>" style="width:<?php echo $wt ?>"></div>
    <div class="bar bar-warning tooltips" title="Break & Lunch: <?php echo $break_lunch; ?>" style="width:<?php echo $bt ?>"></div>
    </div>
	<?php	}else{
		 echo'<div class="progress  progress-striped active" style="height: 5px; margin-top:-10px">			
    <div class="bar bar-danger tooltips" title="Playing with Scooby" style="width: 100%;"></div>
    </div>'; 
	}
	
				}
				else{
				 echo'<div class="progress  progress-striped active" style="height: 5px; margin-top:-10px">			
    <div class="bar bar-danger tooltips" title="Playing with Scooby" style="width: 100%;"></div>
    </div>'; 
				}
				}
				?><br>
					 <!--Progress Bar Stops-->	
					 
					 <table class="table table-bordered table-striped table-condensed" width="100%">
		<tr>
		<td width="10%" style="font-weight: bold;">Remark:</td>
			<td width="80%" class="text-info">
			<ul style="list-style-type: square"><?php 
			
			$search = array(
				'year_id' 	=> $des->year_id,
				'month_id'	=> $des->month_id,
				'user_id' 	=> 0,	
				'date_id' 	=> $des->date_id,	
				);	
			$whereis = array(
				'year_id' 	=> $des->year_id,
				'month_id'	=> $des->month_id,
				'user_id' 	=> $uID,		
				'date_id' 	=> $des->date_id,	
				);	
			$remark = $this->worksheet_model->get_remarks($whereis);	
			$remarks_all = $this->worksheet_model->get_all_remarks($search);	
			if(!empty($remark))
			{
			foreach($remark as $rm)
				{
			echo '<li>';
			echo $rm->remark.'<br>';
			echo '</li>';
				}
			}
			if(!empty($remarks_all))
			{
			foreach($remarks_all as $rma)
				{
			echo '<li>';
			echo $rma->remark.'<br>';
			echo '</li>';
				}
			}
			?></ul>
		</td>
		
			<?php
			if(!empty($remark) && $this->ion_auth->is_admin())
			{
			echo '<td width="10%">';
			foreach($remark as $rm)
			{?>
			<a href="<?php echo site_url('user/worksheet/delete_remark').'/'.$rm->id.'/'.$rm->user_id.'/'.$rm->month_id.'/'.$rm->year_id;?>"><i class="icon-trash"></i></a><br>
			<?php }}
			if(!empty($remarks_all) && $this->ion_auth->is_admin())
			{
			foreach($remarks_all as $rma)
			{?>
			<a href="<?php echo site_url('user/worksheet/delete_remark').'/'.$rma->id;?>"><i class="icon-trash"></i></a><br>
			<?php }
			echo '</td>';
			}?>				
		
		</tr>
			<?php
			if($this->ion_auth->is_admin()){?>
			<i class="icon-thumbs-up"></i><a class="more_remark" data-date="<?= $ws->date_id;?>" style="cursor: pointer">&nbsp;Give remark</a>
			<div class="remark_detail_<?= $ws->date_id;?>" style="display: none">
			<input type="text" name="remark" class="remark_<?= $ws->date_id;?>"/>
			<input type="hidden" name="date" class="dateis_<?= $ws->date_id;?>" value="<?= $ws->date_id; ?>"/>
			<input type="hidden" name="year" class="year" value="<?= $ws->year_id; ?>"/>
			<input type="hidden" name="month" class="month" value="<?= $ws->month_id; ?>"/>
			<input type="hidden" name="user" class="user" value="<?= $ws->user_id; ?>"/>
			<input type="button" value="POST" class="remarks btn btn-success btn-small" data-date="<?= $ws->date_id;?>">
			</div>
			<?php } ?>
		</table>
			</td>
			
			
			
			<td><?php
			
			//$attendance = $this->worksheet_model->get_attendance_timings($user_id,date('y'),date('m'),date('d'));	
			$attendance = $this->worksheet_model->get_attendance_timings($user_id,$ws->year_id,$ws->month_id,$ws->date_id);
			
			foreach($attendance as $at){
				if(isset($at->entry_time))
				{
				echo '<table class="table table-striped table-condensed" width="100%">';
			echo '<tr><td width="40%"><b class="text-danger">Total:</b>&nbsp;</td>';	
				
				echo '<td width="60%">';
				if(!empty($at->exit_time)){
				$dbtime_ent = explode(':',$at->entry_time);
		 		$dbtot_hre 		= $dbtime_ent[0]*60*60;
				$dbtot_mine		= $dbtime_ent[1]*60;				
				$dbtime_tot_ent = $dbtot_hre + $dbtot_mine;
				
				$dbtime_ext = explode(':',$at->exit_time);
		 		$dbtot_hrb 		= $dbtime_ext[0]*60*60;
				$dbtot_minb		= $dbtime_ext[1]*60;				
				$dbtime_tot_ext = $dbtot_hrb + $dbtot_minb;
				
				$tot=$dbtime_tot_ext-$dbtime_tot_ent;
					
				$bhours 		= floor(abs($tot)/ 3600);
				$bminutes 		= floor((abs($tot) / 60) % 60);
				echo $total_time = $bhours .' hr : '.$bminutes.' min';
				}
				echo '</td></tr>';
				
				echo '<tr><td><b class="text-warning">Office:</b>&nbsp;</td>';
			echo '<td>';
			if(!empty($at->exit_time) && !empty($at->lunch_in_time) && !empty($at->lunch_out_time)){

				
				$dbtime_ent = explode(':',$at->entry_time);
		 		$dbtot_hra 		= $dbtime_ent[0]*60*60;
				$dbtot_mina		= $dbtime_ent[1]*60;				
				$dbtime_tot_ent = $dbtot_hra + $dbtot_mina;
				
				$dbtime_ext = explode(':',$at->exit_time);
		 		$dbtot_hrb 		= $dbtime_ext[0]*60*60;
				$dbtot_minb		= $dbtime_ext[1]*60;				
				$dbtime_tot_ext = $dbtot_hrb + $dbtot_minb;
				
				$dbtime_lit = explode(':',$at->lunch_in_time);
		 		$dbtot_hrc 		= $dbtime_lit[0]*60*60;
				$dbtot_minc		= $dbtime_lit[1]*60;				
				$dbtime_tot_lit = $dbtot_hrc + $dbtot_minc;
				
				$dbtime_lot = explode(':',$at->lunch_out_time);
		 		$dbtot_hrd 		= $dbtime_lot[0]*60*60;
				$dbtot_mind		= $dbtime_lot[1]*60;				
				$dbtime_tot_lot = $dbtot_hrd + $dbtot_mind;
				
				$t=($dbtime_tot_ext-$dbtime_tot_lot)+($dbtime_tot_lit-$dbtime_tot_ent);
					
				$bhours 		= floor(abs($t)/ 3600);
				$bminutes 		= floor((abs($t) / 60) % 60);
				echo $office_time = $bhours .' hr : '.$bminutes.' min';
				}
				echo '</td></tr>';
				
				echo '<tr><td><b class="text-success">Lunch:</b>&nbsp;</td>';
			echo '<td>';
			if(!empty($at->lunch_out_time)){
		
				
				$dbtime_lit = explode(':',$at->lunch_in_time);
		 		$dbtot_hr 		= $dbtime_lit[0]*60*60;
				$dbtot_min		= $dbtime_lit[1]*60;				
				$dbtime_tot_lit = $dbtot_hr + $dbtot_min;
				
				$dbtime_lot = explode(':',$at->lunch_out_time);
		 		$dbtot_hr 		= $dbtime_lot[0]*60*60;
				$dbtot_min		= $dbtime_lot[1]*60;				
				$dbtime_tot_lot = $dbtot_hr + $dbtot_min;
				
				$to=$dbtime_tot_lot-$dbtime_tot_lit;
					
				$bhours 		= floor(abs($to)/ 3600);
				$bminutes 		= floor((abs($to) / 60) % 60);
				echo $lunch_time = $bhours .' hr : '.$bminutes.' min'.'</td></tr>';
			}
			
			echo '<tr><td><b class="text-info">Break:</b></td><td>';
				
				if(!empty($at->exit_time) && !empty($at->lunch_in_time) && !empty($at->lunch_out_time)){
									
				$dbtime_ent = explode(':',$at->entry_time);
		 		$dbtot_hre 		= $dbtime_ent[0]*60*60;
				$dbtot_mine		= $dbtime_ent[1]*60;				
				$dbtime_tot_ent = $dbtot_hre + $dbtot_mine;
				
				$dbtime_ext = explode(':',$at->exit_time);
		 		$dbtot_hrb 		= $dbtime_ext[0]*60*60;
				$dbtot_minb		= $dbtime_ext[1]*60;				
				$dbtime_tot_ext = $dbtot_hrb + $dbtot_minb;
				
				$tot=$dbtime_tot_ext-$dbtime_tot_ent;
									
				$dbtime_lit = explode(':',$at->lunch_in_time);
		 		$dbtot_hr 		= $dbtime_lit[0]*60*60;
				$dbtot_min		= $dbtime_lit[1]*60;				
				$dbtime_tot_lit = $dbtot_hr + $dbtot_min;
				
				$dbtime_lot = explode(':',$at->lunch_out_time);
		 		$dbtot_hr 		= $dbtime_lot[0]*60*60;
				$dbtot_min		= $dbtime_lot[1]*60;				
				$dbtime_tot_lot = $dbtot_hr + $dbtot_min;
				
				$lunch_time=$dbtime_tot_lot-$dbtime_tot_lit;
				
				$break_time = ($tot - $dbtime_tot)- $lunch_time;
					
				$bhours 		= floor(abs($break_time)/ 3600);
				$bminutes 		= floor((abs($break_time) / 60) % 60);
				
				if($dbtime_tot<=$tot)
				{
				echo $break_time  = $bhours .' hr : '.$bminutes.' min';
				}else{
					echo 'Haha !! <br>Wrong Entry';
				}
				}
				
				echo '</td></tr>';
				
				echo '<tr><td><b class="text-warning">Work: </b></td>';
				echo '<b class="text-success">';	
				
				$hours 			= floor($dbtime_tot/ 3600);
				$minutes 		= floor(($dbtime_tot / 60) % 60);
				echo '<td>'.$sumtime 	= $hours .' hr : '.$minutes.' min'.'</td></tr>';
			
				echo'</b>';
				echo'</table>';
				}}
				?>
			</td>
			
		</tr>		
		<?php }?>
	</tbody>
	</form>
</table>

<hr />

</div>
<div class="span2">


		<?php $cal_info = getdate();$year_var = $cal_info['year'];$year_var = substr($year_var, 2);$month_var = $cal_info['month'];$month_var = date('m',strtotime($month_var));?>
		
		<a href="<?php echo site_url('user/salary/salary_slip').'/'. $month_var . '/'. $year_var ?>">Salary Slip</a> /
		<a href="<?php echo site_url('user/attendance/index').'/' . $year_var . '/' . $month_var ?>">My Attendance</a>

	<h2 class="widget-name">Links</h2>	
	<?php foreach($year_lst as $year_lst)
			{ 
	?>
	<?php if(isset($user_id))
			{ 
	?>
	<div class="accordion" id="accordion1">
		<div class="accordion-group">
			<div class="accordion-heading">
				<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion1" href="#collapse<?php echo($year_lst->year_id);?>">
					<?php echo("20" . $year_lst->year_id);?>	
				</a>
			</div>
			<div id="collapse<?php echo($year_lst->year_id);?>" class="accordion-body collapse <?php $year_info = getdate();$current_year ="20" . $year_lst->year_id; if(($year_info['year']) == $current_year) {echo("in");}?>">
				<div class="accordion-inner">
					<?php $month_lst = $this->worksheet_model->get_worksheet_months($year_lst->year_id);?>
					
					<ul>
					<?php foreach($month_lst as $month_lst){ ?>
					<li>	
					<?php if(isset($user_id)){ ?>
					<a href="<?php echo site_url('user/worksheet/index').'/'.$user_id.'/'.$year_lst->year_id.'/'.$month_lst->month_id?>"><?= date("F", mktime(0, 0, 0, $month_lst->month_id, 10))?></a>			
					<?php }else{ ?>
					<a href="<?php echo site_url('user/worksheet/index').'/'.$year_lst->year_id.'/'.$month_lst->month_id?>"><?= date("F", mktime(0, 0, 0, $month_lst->month_id, 10))?></a>			
					<?php }?>
					</li>
					<?php }?>
					</ul>
					
				</div>
			</div>
		</div>
	</div>	
	
	<?php }?>
	<?php }?>
<h2 class="widget-name">Notice</h2>
<?php			
			//echo("<pre>");
			
	
			if($this->ion_auth->is_active($user_id) AND !($this->ion_auth->is_client($user_id)))
				{  
					$total_time_average = 0;$present_days = 0;
					foreach($worksheet as $ws)
						{
							$where = array
							(
								'year_id' 	=> 	$ws->year_id,
								'month_id' 	=>	$ws->month_id,				
								'user_id'	=>	$ws->user_id,	
								'date_id'	=> 	$ws->date_id,
							);	
							
							$w_timings = $this->all_attendance_model->get_worksheet_timings_id($ws->user_id,$ws->date_id,$ws->month_id,$ws->year_id);
							$worksheet_halfday = $this->worksheet_model->get_single_setting('worksheet_halfday');				
							//echo("<pre>");
							//print_r($ws->date_id);	
							
							
							//echo("Date: " . $ws->date_id);
							//$worksheet_halfday = 4;
							// converting time to seconds				
							
							$wh = ($worksheet_halfday*60*60);				
							$tot = 0;
							$total_time = 0;
				
							foreach($w_timings as $w_timings)
								{
									//echo("<pre>");
									//print_r($w_timings->time_spent);
									
									if(isset($w_timings))
										{					
											$time_explode = explode(':',$w_timings->time_spent);					
					
											$tot_hr	= $time_explode[0]*60*60;	
											$tot_min = $time_explode[1]*60;
											$tot = $tot_hr + $tot_min;					
											$total_time += $tot;								
										}			
								}
											

								
							if($total_time >= $wh)
								{
									$present_days +=1;					
									$hr	= floor($total_time / 3600);
									$min = floor(($total_time / 60) % 60);
									if($min <=9)
										{
											$min = $min . "0";
										}
									$hr.':'.$min;					
									$total_time_average += $total_time;
								}				
						}
					if($total_time_average > 0)
						{				
							$avg_time = $total_time_average / $present_days+1;
							$a_hr = floor($avg_time / 3600);
							$a_min = floor(($avg_time / 60) % 60);
							if($a_min <=9)
								{
									$a_min = $a_min . "0";
								}
							$avgTime =  $a_hr.':'.$a_min;
						}
					else
						{
							$avgTime = '0';
						}
					$worksheet_average = $this->worksheet_model->get_single_setting('worksheet_average');
					$worksheet_average	= ($worksheet_average*60*60);
					if($avg_time < $worksheet_average)
						{
							
					?>
					<div class="alert alert-error">
						<button type="button" class="close" data-dismiss="alert">&times;</button>
						<h4>Warning!</h4>
							Your worksheet average time <?php echo $avgTime;?> is less than required.
					</div>
					<?php
						}
				}	
			?>	
		<div class="alert alert-error">
						<button type="button" class="close" data-dismiss="alert">&times;</button>
						<h4>Warning!</h4>
		Please fill your worksheet for the following dates
		<?php
		foreach($unfilled_worksheet as $unfilled_worksheet)
						{
							echo preg_replace("/[^0-9,.]/", "", $unfilled_worksheet);
							echo(", ");
						}
				
		?>
		</div>	

</div>
</div>



<script type="text/javascript">

function formSubmit(){
$('#loading-overlay').show();
$('#loading').show();
var date_id = $('#date').val();
var task_details= $('#desc').val();
var time_hr= $('#hr').val();
var time_min= $('#min').val();
$.post('<?= site_url('user/worksheet/save');?>',
				{
				date_id:date_id,desc:task_details,hour:time_hr,time_min:time_min
				}, function(time)
				{				
				$('#loading-overlay').hide();
				$('#loading').hide();				
				alert('Worksheet has been updated');
				window.location.reload()
				$('#date').val('');
				$('#desc').val('');
				$('#hr').val('00');
				$('#min').val('00');
				})
}
//-->
</script>

<?php
$data = $this->worksheet_model->get_hash_fields();	
			$variables=json_encode($data);
?>

<script type="text/javascript">

/*	$('.multiple_subtask').live('keydown',function(e){
     var p = e.keyCode;	
	 var i = $('#insert_subtask p').size() + 1;	 
     if(p==13){
	 	
		 $("#insert_subtask").append('<p> <input type="text" class="datepicker multiple_subtask details" name="date['+i+']" value="" /> <input type="text" class="multiple_subtask span6 tag1" name="task_details['+i+']" placeholder="your task description..." id=desc'+i+' /> <input type="text" class="multiple_subtask span1" name="time_hr['+i+']" id="hr" value="00"/> <input type="text" class="multiple_subtask span1" name="time_min['+i+']" id="min" value="00"/></p>');
		$('.details').val($('#date').val());
		 $('#desc'+i+'').focus();
     }
	 else if(p==46 ){	 	
	 	if( i > 1)
				{
					$(this).parents('p').remove();
					i--;
					var rm = '#desc'+(i-1)+'';					
					$(rm).focus();					
				}
				return false;
	 }
 });*/
 

  
 
  $('#save_multiple').click(function(){
 	$('#multiple_form').submit();	
 });
 
 $('.get_worksheet').click(function(event) {	
  event.preventDefault();
  $.get(this.href, function(html) {
  $(html).appendTo('body').modal(); 
  });
});	

  $('#verify').click(function(){
 			$('#multiple_submit').submit();	
 			});

function select_all(){
	if(document.getElementById('all').checked){
		$('.alls').attr('checked','checked');
	}else{
		$('.alls').prop('checked', false);
		}
	}

var tag=<?php
$data = $this->worksheet_model->get_hash_fields();	
echo $variables=json_encode($data);
?>

  $(function(){
    $(".tag").tagInput({
      tags:tag,
     // jsonUrl:"tags.json",	
     // sortBy:"frequency",      
      tagSeparator:" ",
      autoFilter:true,
      autoStart:false,
      //suggestedTagsPlaceHolder:$("#suggested"),
      boldify:true,
    });
	});

	    $('.test').on( 'keydown', function ( e ) {
    	if ( e.keyCode === 13 ) {
        $('.test1').toggle();
		$('#desc1').focus();
    	}
		});
		       
		$('.test1').on( 'keydown', function ( e ) {
    	if ( e.keyCode === 13 ) {
        $('.test2').toggle();
    	$('#desc2').focus();
		}else if(e.keyCode == 46 ){
	 	$('.test1').hide();
		$('#desc0').focus();
		}
		});
		
		$('.test2').on( 'keydown', function ( e ) {
    	if ( e.keyCode === 13 ) {
        $('.test3').toggle();
    	$('#desc3').focus();
		}else if(e.keyCode == 46 ){
	 	$('.test2').hide();
		$('#desc1').focus();
		}
		});
		
		$('.test3').on( 'keydown', function ( e ) {
    	if ( e.keyCode === 13 ) {
        $('.test4').toggle();
    	$('#desc4').focus();
		}else if(e.keyCode == 46 ){
	 	$('.test3').hide();
		$('#desc2').focus();
		}
		});
		
		$('.test4').on( 'keydown', function ( e ) {
    	if ( e.keyCode === 13 ) {
        $('.test5').toggle();
    	$('#desc5').focus();
		}
		else if(e.keyCode == 46 ){
	 	$('.test4').hide();
		$('#desc3').focus();
		}
		});
		
		$('.test5').on( 'keydown', function ( e ) {
    	if ( e.keyCode === 13 ) {
        $('.test6').toggle();
    	$('#desc6').focus();
		}else if(e.keyCode == 46 ){
	 	$('.test5').hide();
		$('#desc4').focus();
		}
		});
		
		$('.test6').on( 'keydown', function ( e ) {
    	if ( e.keyCode === 13 ) {
        $('.test7').toggle();
    	$('#desc7').focus();
		}else if(e.keyCode == 46 ){
	 	$('.test6').hide();
		$('#desc5').focus();
		}
		});
		
		$('.test7').on( 'keydown', function ( e ) {
    	if ( e.keyCode === 46 ) {
        $('.test7').hide();
    	$('#desc6').focus();
		}
		});
		
		$('.more_remark').click(function(){
			var date=$(this).attr("data-date");
			if(date)
			{
			$('.remark_detail_'+date).show();
    		$('.remark_detail_'+date).focus();	
 			}
			$('.remark_detail_'+date).on( 'keydown', function ( e ) {
    	if ( e.keyCode === 46 ) {
        $('.remark_detail_'+date).hide();
		}
		});
			});
		
		
		
		$(".remarks").click(function()
		{
			var date=$(this).attr("data-date");
			//alert("hello");
			var user = $(".user").val();
			var date_id = $(".dateis_"+date).val();
			var month_id = $(".month").val();
			var year_id = $(".year").val();
			var remark = $(".remark_"+date).val();
			
			//alert(user);
			$('#loading-overlay').show();
			$('#loading').show();
			$.post('<?= site_url('user/worksheet/add_remarks');?>',
				{
					user_id : user,date_id:date_id,month_id:month_id,year_id:year_id,remark:remark
				}, function(data)
				{	
				$('#loading-overlay').hide();
				$('#loading').hide();
				$('.remark_'+date).val("");
				alert("Your Remark Has been posted");
				window.location.reload();
				})
				
		})
		
		$(".red").click(function()
		{
			//alert("hello");
			var id = $(this).attr('data-id');
			var color = $(this).attr('data-color');
			
			$('#loading-overlay').show();
			$('#loading').show();
			$.post('<?= site_url('user/worksheet/add_colors');?>',
				{
					id:id,color:color
				}, function(data)
				{
				$('#loading-overlay').hide();
				$('#loading').hide();
				window.location.reload();
				})
				
		})
		
		$(".green").click(function()
		{
			//alert("hello");
			var id = $(this).attr('data-id');
			var color = $(this).attr('data-color');
		
			$('#loading-overlay').show();
			$('#loading').show();
			$.post('<?= site_url('user/worksheet/add_colors');?>',
				{
					id:id,color:color
				}, function(data)
				{	
				$('#loading-overlay').hide();
				$('#loading').hide();
				window.location.reload();
				})
				
		})
		
		$(".yellow").click(function()
		{
			//alert("hello");
			var id = $(this).attr('data-id');
			var color = $(this).attr('data-color');
	
			$('#loading-overlay').show();
			$('#loading').show();
			$.post('<?= site_url('user/worksheet/add_colors');?>',
				{
					id:id,color:color
				}, function(data)
				{	
				$('#loading-overlay').hide();
				$('#loading').hide();
				window.location.reload();
				})
				
		})

		
</script>